// 本地缓存
class LocalCache {
  setCache(key: string, value: any, isLocal: boolean) {
    if (isLocal) {
      window.localStorage.setItem(key, JSON.stringify(value));
    } else {
      window.sessionStorage.setItem(key, JSON.stringify(value));
    }
  }

  getCache(key: string, isLocal: boolean) {
    if (isLocal) {
      const value = window.localStorage.getItem(key);
      if (value) {
        return JSON.parse(value);
      }
    } else {
      const value = window.sessionStorage.getItem(key);
      if (value) {
        return JSON.parse(value);
      }
    }
  }

  deleteCache(key: string, isLocal: boolean) {
    if (isLocal) {
      window.localStorage.removeItem(key);
    } else {
      window.sessionStorage.removeItem(key);
    }
  }

  clearCache(isLocal: boolean) {
    if (isLocal) {
      window.localStorage.clear();
    } else {
      window.sessionStorage.clear();
    }
  }
}
export default new LocalCache();
